package com.cctc.rds.nrpc.demo.client;

import com.cctc.rds.nrpc.api.client.config.RpcClientConfig;
import com.cctc.rds.nrpc.core.client.NettyRpcClient;
import com.cctc.rds.nrpc.demo.rpc.HelloRpc;
import com.cctc.rds.nrpc.demo.rpc.HelloRpcResponse;
import com.cctc.rds.nrpc.demo.rpc.HelloRpcReuqest;
import com.cctc.rds.nrpc.demo.rpc.router.ClientRpcRouter;
import com.cctc.rds.nrpc.demo.rpc.router.impl.HelloClientRpcRouter;

public class NettyRpcClientDemo {

    public static void main(String[] args) {
        NettyRpcClient client = new NettyRpcClient();
        RpcClientConfig config = RpcClientConfig.builder()
                .remoteIp("127.0.0.1")
                .remotePort(9000)
                .connectionTimeoutMs(75)
                .waitResponseTimeoutMs(75)
                .failRetryConnectMs(75)
                .idleStateMs(75)
                .build();
        client.start(config);

        ClientRpcRouter<HelloRpc> router = new HelloClientRpcRouter(client);
        HelloRpcReuqest reuqest = HelloRpcReuqest.builder().a(1).b(2).build();
        HelloRpcResponse response = router.route().sum(reuqest);
        System.out.println(response.getSum());
    }

}
